package Week5;

import java.util.ArrayList;
import java.util.Scanner;

interface GeneralStack{
	Object push(Object item);            
	Object pop();                 
	Object peek();                
	public boolean empty();
	public int size();    
}
class ArrayListGeneralStack implements GeneralStack{
	ArrayList<Object> list=new ArrayList<Object>();
	@Override
	public Object push(Object item) {
		if(item==null)
			return null;
		else 
		{
			list.add(item);
			return item;
		}
	}
	@Override
	public Object pop() {
		if(list.size()==0)
			return null;
		else 
		{			
			Object a=list.get(list.size()-1);
			list.remove(list.size()-1);
			return a;			
		}
	}
	@Override
	public Object peek() {
		if(!list.isEmpty())
			return list.get(list.size()-1);
		else 
			return null;
	}
	@Override
	public boolean empty() {
		if(list.size()==0)
			return true;
		else 
			return false;
	}
	@Override
	public int size() {
		return list.size();
	}
	@Override
	public String toString() {
		System.out.println(list);
		return null;
	}	
}

class Car{
	private int id;
	private String name;
	Car(int id,String name){
		this.id=id;
		this.name=name;
	}	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getMame() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Override
	public String toString() {
		return "Car [id=" + id + ", name=" + name + "]";
	}	
}

public class Main3 {
	public static void main(String[] arge){
		Scanner in=new Scanner(System.in);
		while(true){
			String str=in.next();
			if(str.equals("quit"))
				break;		
			else
			{
				int m=in.nextInt();
				int n=in.nextInt();				
				if(str.equals("Integer")){
					System.out.println("Integer Test");
					ArrayListGeneralStack stack=new ArrayListGeneralStack();
					for(int i=0;i<m;i++){
						int a=in.nextInt();
						stack.push(a);
						System.out.println("Push:"+stack.peek());
					}
					for(int j=0;j<n;j++){
						Integer b=(Integer) stack.pop();
						System.out.println("Pop:"+b);
					}
					stack.toString();	
					int a=0;
					for(int i=0;i<=stack.size()+1;i++){
						if(!stack.empty()){
							Integer b=(Integer) stack.pop();
							a=a+b;
						}	
					}
					System.out.println("sum="+a);
					System.out.println(stack.getClass().getInterfaces()[0]);						
				}
				if(str.equals("Double")){
					System.out.println("Double Test");
					ArrayListGeneralStack stack=new ArrayListGeneralStack();
					for(int i=0;i<m;i++){
						Double a=in.nextDouble();
						stack.push(a);					
						System.out.println("Push:"+stack.peek());
					}
					for(int j=0;j<n;j++){
						System.out.println("Pop:"+stack.peek());
						stack.pop();						
					}
					stack.toString();
					Double a=0.0;
					for(int i=0;i<=stack.size()+1;i++){
						if(!stack.empty()){
							Double b=(Double) stack.pop();						
							a=a+b;
						}					
					}
					System.out.println("sum="+a);			
					System.out.println(stack.getClass().getInterfaces()[0]);
				}
				if(str.equals("Car")){
					System.out.println("Car Test");
					ArrayListGeneralStack stack=new ArrayListGeneralStack();				
					for(int i=0;i<m;i++){
						Car a = new Car(in.nextInt(),in.next());
						stack.push(a);
						System.out.println("Push:"+stack.peek());
					}
					for(int j=0;j<n;j++){
						Car b=(Car) stack.peek();
						stack.pop();
						System.out.println("Pop:"+b);
					}
					stack.toString();
					for(int i=0;i<stack.size();i++){
						if(!stack.empty()){
							Car b=(Car) stack.pop();
							String name=b.getMame();
							System.out.println(name);
						}					
					}
					System.out.println(stack.getClass().getInterfaces()[0]);
					
				}
			}				
		}
	}
}
